<?php
/**
 * Created by PhpStorm.
 * User: alinejun
 * Date: 2019/2/17
 * Time: 12:34
 */
namespace app\index\controller;
use app\common\logic\City;
use app\common\model\Collection;

/**
 * 前端首页控制器
 */
class Scenery extends IndexBase{
    public function __construct()
    {
        parent::__construct();
    }
    public function index()
    {
        $city_id = session('city_id');
        $cate_id = input('cate_id') ? input('cate_id') : 0;
        //先找出该城市下所有的城市
        $city_id and  $city_ids = $this->logicCity->getCityList(['pid'=>$city_id])->toArray();
        $city_ids = array_column($city_ids,'id');
        array_push($city_ids,(int)$city_id);
        //该城市下面的所有子城市都包括
        $where['city_id'] = ['in',$city_ids];
        empty($cate_id) or $where['category_id'] = $cate_id;
        $category_list =  $this->logicScenery->getSceneryType($where);

        $this->assign('cate_id',$cate_id);
        $this->assign('category_list',$category_list);
        $list =  $this->logicScenery->getSceneryList($where);
        $this->assign('list',$list);
        return $this->fetch('index');
    }

    // 详情
    public function details($id = 41)
    {

        $where = [];

        !empty((int)$id) && $where['id'] = $id;

        $data = $this->logicScenery->getSceneryInfo($where);
        $city_id = session('city_id');
        $cate_id = input('cate_id') ? input('cate_id') : 0;
        //先找出该城市下所有的城市
        $city_id and  $city_ids = $this->logicCity->getCityList(['pid'=>$city_id])->toArray();
        $city_ids = array_column($city_ids,'id');
        array_push($city_ids,(int)$city_id);
        //该城市下面的所有子城市都包括
        $map['city_id'] = ['in',$city_ids];
        $scenery_list = $this->logicScenery->getSceneryList($map,'a.*',' RAND() ');
        //dump($scenery_list->toArray());exit;
        $this->assign('scenery_list',$scenery_list->toArray()['data']);
        $data['content'] = html_entity_decode($data['content']);
        $this->assign('scenery_info', $data);
        return $this->fetch('detail');
    }
}